//
//  HZCycleView.m
//  MyDoctor
//
//  Created by 黑眼圈 on 16/5/4.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "HZCycleView.h"


@implementation HZCycleView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        //设置并添加子控件
        [self setupUI];
    }
    return self;
}

#pragma mark -
#pragma mark    设置并添加子控件
-(void)setupUI{

    
    //创建scrollerView
    CycleScrollView *cycleScrollView = [[CycleScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 200) animationDuration:1];

    //总计有几页
    cycleScrollView.totalPagesCount = ^(){
        NSInteger count = 3;
        return count;
    };
    //点击的时候回调（一定要有返回contentView）
    cycleScrollView.TapActionBlock = ^(NSInteger pageIndex){
        NSLog(@"你好");
    };
    
    //返回每个页面对应得view
    cycleScrollView.fetchContentViewAtIndex = ^(NSInteger pageIndex){
        
        //拼接图片字符串
        NSString *string = [NSString stringWithFormat:@"h%ld",(long)pageIndex+1];
        
        //创建图片框
        UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:string]];
        
        //设置图片和轮播器一样大
        imageView.bounds = CGRectMake(0, 0, SCREENW, 200);
        
        return imageView;
    };
    
    //设置scrollView的属性
    cycleScrollView.scrollView.showsHorizontalScrollIndicator = NO;
    cycleScrollView.scrollView.bounces = NO;
    
    //添加
    [self addSubview:cycleScrollView];
    
}
















@end
